//
//  MyGetSiscountCouponVC.m
//  phmall
//
//  Created by admin on 2017/11/23.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "MyGetDiscountCouponVC.h"
#import "GetDiscountCouponCell.h"
#import "CouponPageVC.h"
#import "Orderheader.h"
@interface MyGetDiscountCouponVC ()<UITableViewDelegate,UITableViewDataSource>{
    Orderheader *_headView;
}
@property(strong,nonatomic)UITableView *myTableview;
@end

@implementation MyGetDiscountCouponVC
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navBarBgAlpha=@"1.0";
    // 改变NavBar顶层View的颜色
    self.navigationController.navigationBar.barTintColor =  [UIColor whiteColor];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUI];
    self.title=Localized(@"优惠券");
   
    
    
    UIBarButtonItem* leftBar=[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(leftBarAction)];
    self.navigationItem.leftBarButtonItem=leftBar;
    // Do any additional setup after loading the view.
}
-(void)setUI{

    __weak typeof(self) weakSelf = self;
    _headView = [[Orderheader alloc]init];
    _headView.backgroundColor=[UIColor colorWithHexString:@"#E7EBEE"];
    [self.view addSubview:_headView];
    [_headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(0);
        make.left.right.equalTo(self.view);
        make.height.offset(40);
    }];
    _headView.backgroundColor=[UIColor colorWithHexString:@"#f8fafd"];
    _headView.itemClickAtIndex = ^(NSInteger index){
        [weakSelf adjustScrollView:index];
    };
    _headView.items = @[@"未使用",@"已过期",@"已使用"];
    
    [self.view addSubview:self.myTableview];
    [self.myTableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(40);
        make.left.right.equalTo(self.view).priorityHigh();
        make.bottom.equalTo(self.view).with.offset(-49-self.tabBar_height).priorityHigh();
    }];
    _headView.items = @[Localized(@"未使用"),Localized(@"已过期"),Localized(@"已使用")];
    
    UIButton *get=[UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:get];
    get.titleLabel.font=[UIFont systemFontOfSize:16];
    [get setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [get setTitle:Localized(@"领券中心") forState:UIControlStateNormal];
    get.backgroundColor=[UIColor whiteColor];
    [get addTarget:self action:@selector(getAction:) forControlEvents:UIControlEventTouchUpInside];
    [get mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.bottom.offset(-self.tabBar_height);
        make.height.offset(49);
    }];
    UIView *line=[[UIView alloc]init];
    [get addSubview:line];
    line.backgroundColor=[UIColor colorWithHexString:@"#ECEBEC"];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.offset(0);
        make.height.offset(0.5);
    }];
}
-(void)getAction:(UIButton *)sender{
    self.hidesBottomBarWhenPushed=YES;
    CouponPageVC *getSiscountCoupon=[[CouponPageVC alloc]init];
    [self.navigationController pushViewController:getSiscountCoupon animated:YES];
}
#pragma mark-通过点击button来改变scrollview的偏移量
-(void)adjustScrollView:(NSInteger)index
{
    switch (index) {
        case 0:
//            [self loadDataWithorder:@"0"];
            break;
        case 1:
//            [self loadDataWithorder:@"1"];
            break;
        case 2:
//            [self loadDataWithorder:@"3"];
            break;
   
        default:
            break;
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 180;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 5;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    GetDiscountCouponCell *cell=[GetDiscountCouponCell theShareCellWithTableView:tableView];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    //分割线补全
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}

//MARK:-GETTER
- (UITableView *)myTableview{
    if (!_myTableview) {
        _myTableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _myTableview.delegate = self;
        _myTableview.dataSource = self;
        _myTableview.backgroundColor=[UIColor groupTableViewBackgroundColor];
        _myTableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _myTableview.showsVerticalScrollIndicator=NO;
        _myTableview.scrollEnabled = YES;
    }
    return _myTableview;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
